package com.hc.mapper;

import com.hc.entity.Environmentmv;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author LiuZhiHao
 * @since 2019-12-04
 */
public interface EnvironmentmvMapper extends BaseMapper<Environmentmv> {

    @Select("select time_interval,mean_value,humidity_mv,voc_mv,pm2_mv,pm10_mv,oxygen_mv,cd_mv,fd_mv,pressure_mv ,equipment_name from  environmentmv WHERE  DATE_FORMAT(input_time,'%Y-%m-%d')=DATE_FORMAT(#{date}, '%Y-%m-%d')")
    List<Environmentmv> selectEnvironmentmvday(@Param("date") String date);

    @Select("select time_interval,mean_value,humidity_mv,voc_mv,pm2_mv,pm10_mv,oxygen_mv,cd_mv,fd_mv,pressure_mv ,equipment_name from  environmentmv WHERE  DATE_FORMAT(input_time,'%Y-%m-%d')=DATE_FORMAT(#{date}, '%Y-%m-%d') limit 1")
    List<Environmentmv> selectEnvironmentmvdayLimit(@Param("date") String date);


    @Select("DELETE  from  environmentmv WHERE  DATE_FORMAT(input_time,'%Y-%m-%d')=DATE_FORMAT(#{date}, '%Y-%m-%d')")
    void deleteEnvironmentmvdayLimit(@Param("date") String date);



    @Select("SELECT\n" +
            "\t* \n" +
            "FROM\n" +
            "\tenvironmentmv \n" +
            "WHERE\n" +
            "\tequipment_name = #{equipment_name} \n" +
            "\tAND DATE_FORMAT( input_time, '%Y-%m-%d' ) BETWEEN DATE_FORMAT( #{startTime}, '%Y-%m-%d' ) \n" +
            "\tAND DATE_FORMAT( #{endTime}, '%Y-%m-%d' );")
    List<Environmentmv> selectEnvironmentmvmonth(@Param("equipment_name")String equipment_name,@Param("startTime")String startTime,@Param("endTime")String endTime);

    @Select("SELECT\n" +
            "\tt1.equipmentno AS equipmentNo,\n" +
            "\tt1.equipmentname AS equipmentName,\n" +
            "\tcurrenttemperature as currenttemperature,\n" +
            "\tt2.currentcarbondioxide as currentcarbondioxide,\n" +
            "\tt2.currento2 as currento2,\n" +
            "\tcurrentairflow as currentairflow,\n" +
            "\tcurrenthumidity as currenthumidity,\n" +
            "\tcurrentvoc as currentvoc,\n" +
            "\tcurrentformaldehyde as currentformaldehyde,\n" +
            "\tt2.currentpm25 as currentpm25,\n" +
            "\tt2.currentpm10 as currentpm10\n" +
            "FROM\n" +
            "\tmonitorequipment t1\n" +
            "\tLEFT JOIN ${tableName} t2 ON t1.equipmentno = t2.equipmentno  AND t2.inputdatetime BETWEEN #{startTime} AND #{endTime}\n" +
            "\tRIGHT JOIN monitorinstrument t3 on t3.equipmentno =t2.equipmentno\n" +
            "\t \n" +
            "WHERE\n" +
            "\tt1.equipmenttypeid = '1' \n" +
            "\tAND t1.hospitalcode = 'H0006' ")
    List<Environmentmv> getEnvironmentmvBydate(@Param("tableName")String tableName,@Param("startTime")String startTime, @Param("endTime")String endTime);

    @Select("SELECT\n" +
            "\tt1.equipmentno AS equipmentNo,\n" +
            "\tt1.equipmentname AS equipmentName,\n" +
            "\tcurrenttemperature as currenttemperature,\n" +
            "\tt2.currentcarbondioxide as currentcarbondioxide,\n" +
            "\tt2.currento2 as currento2,\n" +
            "\tcurrentairflow as currentairflow,\n" +
            "\tcurrenthumidity as currenthumidity,\n" +
            "\tcurrentvoc as currentvoc,\n" +
            "\tcurrentformaldehyde as currentformaldehyde,\n" +
            "\tt2.currentpm25 as currentpm25,\n" +
            "\tt2.currentpm10 as currentpm10\n" +
            "FROM\n" +
            "\tmonitorequipment t1\n" +
            "\tLEFT JOIN monitorequipmentlastdata_20200604 t2 ON t1.equipmentno = t2.equipmentno  AND t2.inputdatetime BETWEEN #{startTime} AND #{endTime}\n" +
            "\tRIGHT JOIN monitorinstrument t3 on t3.equipmentno =t2.equipmentno\n" +
            "\t \n" +
            "WHERE\n" +
            "\tt1.equipmenttypeid = '1' \n" +
            "\tAND t1.hospitalcode = 'H0006' ")
    List<Environmentmv> getEnvironmentmvBydate64(@Param("startTime")String startTime, @Param("endTime")String endTime);
}
